package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import java.util.Arrays;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * aip数据导出类型:按年度,选数据
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum AipExportTypeEnum {

  /** 按年度 */
  YEAR(1, "按年度"),
  /** 整理 */
  SELECT(2, "选数据"),
  ;
  private Integer type;
  private String desc;

  public static AipExportTypeEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.type.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到aip数据导出类型：" + type));
  }

  public static AipExportTypeEnum convert(String desc) {
    return Arrays.stream(values()).filter(x -> x.desc.equals(desc)).findAny().orElse(YEAR);
  }

  @JsonCreator
  public static AipExportTypeEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.type, type)).findAny().orElse(null);
  }
}
